package day20171222;

import com.sun.org.apache.xpath.internal.SourceTree;

import java.io.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Test {
    public static void main(String[] args) {

        String path1 = "D:\\面向对象程序设计Java2016级信本1班实验4";
        String path2 = "D:\\names.txt";
        BufferedWriter bufferedWriter = null;
        BufferedReader bufferedReader = null;

        try {
            bufferedWriter = new BufferedWriter(new FileWriter(path2));

            File file = new File(path1);
            File[] files = file.listFiles();

            for (File f : files){
                String fileName = f.getName();

                //面向对象程序设计Java2016级信本1班1606101002肖林实验4
                Matcher matcher = Pattern.compile("信本1班(\\d+.*)实验").matcher(fileName);
                while (matcher.find()){
                    System.out.println(matcher.group(1));
                    bufferedWriter.write(matcher.group(1));
                }

            }

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                bufferedWriter.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}
